package com.unity3d.player;

import android.app.*;
import android.content.*;
import android.graphics.drawable.*;
import android.text.*;
import android.view.*;
import android.view.inputmethod.*;
import android.widget.*;

public final class h extends Dialog implements TextWatcher, View.OnClickListener
{
    private static int c = 1627389952;
    private static int d = -1;
    private static int e = 134217728;
    private static int f = 67108864;
    private Context a;
    private UnityPlayer b;

    public h(final Context a, final UnityPlayer b, final String s, final int n, final boolean b2, final boolean b3, final boolean b4, final String s2) {
        super(a);
        this.a = null;
        this.b = null;
        this.a = a;
        this.b = b;
        this.getWindow().setGravity(80);
        this.getWindow().requestFeature(1);
        this.getWindow().setBackgroundDrawable((Drawable)new ColorDrawable(0));
        this.setContentView(this.createSoftInputView());
        this.getWindow().setLayout(-1, -2);
        this.getWindow().clearFlags(2);
        if (g.a) {
            this.getWindow().clearFlags(h.e);
            this.getWindow().clearFlags(h.f);
        }
        final EditText editText = (EditText)this.findViewById(1057292289);
        final Button button = (Button)this.findViewById(1057292290);
        this.a(editText, s, n, b2, b3, b4, s2);
        button.setOnClickListener((View.OnClickListener)this);
        editText.setOnFocusChangeListener((View.OnFocusChangeListener)new View.OnFocusChangeListener() {
            public final void onFocusChange(final View view, final boolean b) {
                if (b) {
                    h.this.getWindow().setSoftInputMode(5);
                }
            }
        });
    }

    private static int a(final int n, final boolean b, final boolean b2, final boolean b3) {
        int n2 = 0;
        int n3;
        if (b) {
            n3 = 32768;
        }
        else {
            n3 = 0;
        }
        int n4;
        if (b2) {
            n4 = 131072;
        }
        else {
            n4 = 0;
        }
        if (b3) {
            n2 = 128;
        }
        final int n5 = n3 | n4 | n2;
        if (n < 0) {
            return n5;
        }
        if (n > 7) {
            return n5;
        }
        return (new int[] { 1, 16385, 12290, 17, 2, 3, 97, 33 })[n] | n5;
    }

    private String a() {
        final EditText editText = (EditText)this.findViewById(1057292289);
        if (editText == null) {
            return null;
        }
        return editText.getText().toString().trim();
    }

    private void a(final EditText editText, final String text, final int n, final boolean b, final boolean b2, final boolean b3, final String hint) {
        editText.setImeOptions(6);
        editText.setText((CharSequence)text);
        editText.setHint((CharSequence)hint);
        editText.setHintTextColor(h.c);
        editText.setInputType(a(n, b, b2, b3));
        editText.addTextChangedListener((TextWatcher)this);
        editText.setClickable(true);
        if (!b2) {
            editText.selectAll();
        }
    }

    private void a(final String s, final boolean b) {
        Selection.removeSelection((Spannable)((EditText)this.findViewById(1057292289)).getEditableText());
        this.b.reportSoftInputStr(s, 1, b);
    }

    public final void a(final String text) {
        final EditText editText = (EditText)this.findViewById(1057292289);
        if (editText != null) {
            editText.setText((CharSequence)text);
            editText.setSelection(text.length());
        }
    }

    public final void afterTextChanged(final Editable editable) {
        this.b.reportSoftInputStr(editable.toString(), 0, false);
    }

    public final void beforeTextChanged(final CharSequence charSequence, final int n, final int n2, final int n3) {
    }

    protected final View createSoftInputView() {
        final RelativeLayout relativeLayout = new RelativeLayout(this.a);
        relativeLayout.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
        relativeLayout.setBackgroundColor(h.d);
        final EditText editText = new EditText(this.a) {
            public final boolean onKeyPreIme(final int n, final KeyEvent keyEvent) {
                if (n == 4) {
                    final h a = h.this;
                    a.a(a.a(), true);
                    return true;
                }
                return n == 84 || super.onKeyPreIme(n, keyEvent);
            }

            public final void onWindowFocusChanged(final boolean b) {
                super.onWindowFocusChanged(b);
                if (b) {
                    ((InputMethodManager)h.this.a.getSystemService("input_method")).showSoftInput((View)this, 0);
                }
            }
        };
        final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -2);
        layoutParams.addRule(15);
        layoutParams.addRule(0, 1057292290);
        editText.setLayoutParams((ViewGroup.LayoutParams)layoutParams);
        editText.setId(1057292289);
        relativeLayout.addView((View)editText);
        final Button button = new Button(this.a);
        button.setText(this.a.getResources().getIdentifier("ok", "string", "android"));
        final RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-2, -2);
        layoutParams2.addRule(15);
        layoutParams2.addRule(11);
        button.setLayoutParams((ViewGroup.LayoutParams)layoutParams2);
        button.setId(1057292290);
        button.setBackgroundColor(0);
        relativeLayout.addView((View)button);
        ((EditText)((View)relativeLayout).findViewById(1057292289)).setOnEditorActionListener((TextView.OnEditorActionListener)new TextView$OnEditorActionListener() {
            public final boolean onEditorAction(final TextView textView, final int n, final KeyEvent keyEvent) {
                if (n == 6) {
                    final h a = h.this;
                    a.a(a.a(), false);
                }
                return false;
            }
        });
        ((View)relativeLayout).setPadding(16, 16, 16, 16);
        return (View)relativeLayout;
    }

    public final void onBackPressed() {
        this.a(this.a(), true);
    }

    public final void onClick(final View view) {
        this.a(this.a(), false);
    }

    public final void onTextChanged(final CharSequence charSequence, final int n, final int n2, final int n3) {
    }
}
